package com.bw.controller.technology;


import com.bw.resp.ResponseResult;
import com.bw.service.technology.IPiOrderPicService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.ServletOutputStream;
import javax.servlet.http.HttpServletResponse;
import java.io.InputStream;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author zhouxin
 * @since 2020-06-22
 */
@RestController
@RequestMapping("orderpic")
public class PiOrderPicController {

    @Autowired
    private IPiOrderPicService orderPicService;

    @GetMapping("/getPic/{itemId}/{code}")
    public ResponseResult getPic(@PathVariable("itemId")Long itemId, @PathVariable("code")String code, HttpServletResponse response){
        ResponseResult result = ResponseResult.SUCCESS();
        try {
            System.out.println("这个是订单编号"+itemId);
            System.out.println("这个是图纸编号"+code);
            InputStream inputStream = orderPicService.getPic(itemId,code);
            int len = inputStream.available();
            byte[] bytes = new byte[1024];
            ServletOutputStream outputStream = response.getOutputStream();
            while ((len=inputStream.read(bytes))!=-1){
                outputStream.write(bytes,0,len);
            }
            outputStream.close();
            System.out.println("查询结束");
        }catch (Exception e){
            e.toString();
        }
        return result;
    }
}
